Scale: Set the correct value alignment
authorTimm Bäder <mail@baedert.org>
Tue, 10 May 2016 16:33:37 +0000 (18:33 +0200)
committerTimm Bäder <mail@baedert.org>
Tue, 10 May 2016 19:24:50 +0000 (21:24 +0200)
We're measuring both the width of the minimal and the maximal value for
the value gadget, but only give the value the minimal width for its
current value, resultnig in an always left-aligned value.

Fix this by assigning the width of the value gadget to the value layout
and letting pango align the text inside the layout.

https://bugzilla.gnome.org/show_bug.cgi?id=766120

gtk/gtkscale.c

index 2223d37f28205931745f335c353ea05b58c48b25..fc0121de97f7704450d409a03f2bd7c85f76394c 100644 (file)
@@ -1903,8 +1903,23 @@ gtk_scale_get_layout (GtkScale *scale)
 
   if (!priv->layout)
     {
+      int min_layout_width;
+
       if (priv->draw_value)
-       priv->layout = gtk_widget_create_pango_layout (GTK_WIDGET (scale), NULL);
+        priv->layout = gtk_widget_create_pango_layout (GTK_WIDGET (scale), NULL);
+
+      gtk_css_gadget_get_preferred_size (priv->value_gadget,
+                                         GTK_ORIENTATION_HORIZONTAL, -1,
+                                         &min_layout_width, NULL,
+                                         NULL, NULL);
+      pango_layout_set_width (priv->layout, min_layout_width * PANGO_SCALE);
+
+      if (priv->value_pos == GTK_POS_LEFT)
+        pango_layout_set_alignment (priv->layout, PANGO_ALIGN_RIGHT);
+      else if (priv->value_pos == GTK_POS_RIGHT)
+        pango_layout_set_alignment (priv->layout, PANGO_ALIGN_LEFT);
+      else
+        pango_layout_set_alignment (priv->layout, PANGO_ALIGN_CENTER);
     }
 
   if (priv->draw_value)